/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.element.force;

import java.util.ArrayList;

import br.ufmg.dees.insane.model.disc.element.Hexahedral;
import br.ufmg.dees.insane.model.disc.element.ParametricElement;
import br.ufmg.dees.insane.model.disc.element.Quadrilateral;
import br.ufmg.dees.insane.model.disc.element.Tetrahedral;
import br.ufmg.dees.insane.model.disc.element.Triangular;
import br.ufmg.dees.insane.model.disc.node.Node;

/**
*A class representing a distributed force.<br>
*It may be a constant distributed force, a trapezoidal distributed force or a triangular distributed force.
*
*@author Nicoliello, Renata & Pitangueira, Roque
*@version 1.0
*@since march 2006
*@see java.util.ArrayList
*/

public class ElementSide implements java.io.Serializable {
	
	private static final long serialVersionUID = 1L;
	protected String label;
	protected ParametricElement element;
	protected ArrayList<Side> sides = new ArrayList<Side>();
	protected int nSide;
	protected Side s;
	protected Side sd;
	
	public ElementSide(ParametricElement element){
		this.element=element;
		
		if (element instanceof Triangular){
			nSide = 3;
		}
		if (element instanceof Quadrilateral){
			nSide = 4;
		}
		if (element instanceof Tetrahedral){
			nSide = 6;
		}
		if (element instanceof Hexahedral){
			nSide = 12;
		}
		
	}
		
	public int getNSide() {
		return nSide;
	}
	
	public void mountSide(){
		sd = new Side(element);
		int cont =1;
			if (sd.getNNodes()==2){
				for(int i=0; i<element.getIncidence().size()-1; i++){
					sd = new Side(element);
					sd.setLabel("Side" + cont);
					//System.out.println("Element ="+element.getLabel());
					//System.out.println(sd.getLabel());
					sd.addNode((Node)element.getIncidence().get(i));
					sd.addNode((Node)element.getIncidence().get(i+1));
					sides.add(sd);
					cont ++;
					//System.out.println("node " +i +"=" +((Node)element.getIncidence().get(i)).getLabel());
					//System.out.println("node " +(i+1) +"=" + ((Node)element.getIncidence().get(i+1)).getLabel());
				
				}
				sd = new Side(element);
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-1));
				sd.addNode((Node)element.getIncidence().get(0));
				//System.out.println("node " +(element.getIncidence().size()-1) +"=" +((Node)element.getIncidence().get(element.getIncidence().size()-1)).getLabel());
				//System.out.println("node " +0 +"=" + ((Node)element.getIncidence().get(0)).getLabel());
				sides.add(sd);
			}
			
			
			if (sd.getNNodes()==3){
				for(int i=0; i<element.getIncidence().size()-2; i++){
					sd = new Side(element);
					sd.setLabel("Side" + cont);
					sd.addNode((Node)element.getIncidence().get(i));
					sd.addNode((Node)element.getIncidence().get(i+1));
					sd.addNode((Node)element.getIncidence().get(i+2));
					sides.add(sd);
					i++;
					cont ++;
					
					
				}
				sd = new Side(element);
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-2));
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-1));
				sd.addNode((Node)element.getIncidence().get(0));
				
				sides.add(sd);
				
			}
			if (sd.getNNodes()==4){
				for(int i=0; i<element.getIncidence().size()-3; i++){
					sd = new Side(element);
					sd.setLabel("Side" + cont);
					sd.addNode((Node)element.getIncidence().get(i));
					sd.addNode((Node)element.getIncidence().get(i+1));
					sd.addNode((Node)element.getIncidence().get(i+2));
					sd.addNode((Node)element.getIncidence().get(i+3));
					sides.add(sd);
					i++;
					i++;
					cont ++;
				}
				sd = new Side(element);
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-3));
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-2));
				sd.addNode((Node)element.getIncidence().get(element.getIncidence().size()-1));
				sd.addNode((Node)element.getIncidence().get(0));
				
				sides.add(sd);
				
				
			}
			
		}
		
		
	
	public void addSide() {
		for(int i=0; i< nSide; i++){
			Side sd = new Side(element);
			sides.add(sd);
		}
		
		
		
		
		
	}
	
	
//********************************************************************************
	
	/** Returns the label of this ElementSide.
	*@return The label of this ElementSide.
	*/
	public String getLabel(){
		return (label);
	};
	
	/** Sets the label of this ElementSide.
	*@param a The label of this ElementSide.
	*/
	public void setLabel(String a){
		label = a;
	};
	
//********************************************************************************
	
	/** Returns the number of sides of this ElementSide.
	*@return The number of sides of this ElementSide.
	*/
	public int getNumberOfSides(){
		return (nSide);
	};
	
	
	
//********************************************************************************
	
	/** Returns the list of sides of this ElementSide.
	*@return The list of sides of this ElementSide.
	*/
	public ArrayList getSidesList() {
		return (sides);
	}




	
	
//********************************************************************************
	

	
//********************************************************************************
}
